package com.suneee.store.dao.impl;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.suneee.context.page.Page;
import com.suneee.orm.GenericDao;
import com.suneee.orm.util.WhereClauseBuilder;
import com.suneee.store.bean.ViewVirtualDepotDTO;
import com.suneee.store.dao.ViewVirtualDepotDao;
import com.suneee.store.entity.ViewVirtualDepot;

@Repository("viewVirtualDepotDao")
public class ViewVirtualDepotDaoImpl extends GenericDao<ViewVirtualDepot, String>implements ViewVirtualDepotDao{

	@Override
	public Page<Map<String,Object>> viewVirtualDepotPage(ViewVirtualDepotDTO dto) {
		WhereClauseBuilder wcb = this.sqlBuild(dto);
		return this.queryForList(wcb.getSql(), dto, wcb.getArgs());
	}
	
	public List<ViewVirtualDepot> selectAll(ViewVirtualDepotDTO dto){
		WhereClauseBuilder wcb = this.sqlBuild(dto);
		return this.executeQuery(wcb.getSql(),  wcb.getArgs());
	}
	
	private WhereClauseBuilder sqlBuild(ViewVirtualDepotDTO dto){
		WhereClauseBuilder wcb =  new WhereClauseBuilder(" select spu_id spuId,sku_id skuId,title,category_name categoryName, category_code categoryCode,spec_one_value specOneValue,spec_two_value specTwoValue,spec_three_value specThreeValue,spec_four_value specFourValue,price,advice_price advicePrice,assigned_stock assignedStock,stock,enterprise_code enterpriseCode,market_price marketPrice,from_type fromType,purchase_price purchasePrice  from v_virtual_depot where 1=1 ");
		wcb.contains("title", dto.getTitle());
		wcb.equals("spu_id",dto.getSpuId());
		wcb.equals("sku_id",dto.getSkuId());
		wcb.equals("category_code",dto.getCategoryCode());
		wcb.equals("enterprise_code",dto.getEnterpriseCode());
		wcb.equals("from_type",dto.getFromType());
		return wcb;
	}
	
	public List<ViewVirtualDepot> exportFile(Integer[] skuId){
		WhereClauseBuilder wcb =  new WhereClauseBuilder(" select * from v_virtual_depot where 1=1");
		List<Object> list = new ArrayList<>();
		Collections.addAll(list, skuId);
		if(null != skuId && skuId.length > 0){
			wcb.in("sku_id", list);
		}
		return this.executeQuery(wcb.getSql(),wcb.getArgs());
	}

}
